package com.boarsoft.boar.flow;

import java.util.List;

import org.springframework.stereotype.Component;

import com.boarsoft.boar.entity.SoaNexus;
import com.boarsoft.common.Util;
import com.boarsoft.common.dao.PagedResult;
import com.boarsoft.hibernate.biz.SimpleBizImpl;

@Component("flowReferenceBiz")
public class FlowReferenceBizImpl extends SimpleBizImpl implements FlowReferenceBiz {
	@Override
	public PagedResult<SoaNexus> list(String objCode0, String objType1, String key, String orderBy, int pageNo, int pageSize) {
		StringBuilder sb = new StringBuilder();
		sb.append(" from ").append(SoaNexus.class.getName()).append(" n");
		sb.append(" where n.objCode0='").append(objCode0).append("' and n.objType1='");
		sb.append(objType1).append("'");
		String ql = sb.toString();
		int total = dao.getTotal("select count(id)".concat(ql));
		//
		if (Util.strIsNotEmpty(orderBy)) {
			// String ob = Util.array2str(("e." + orderBy).replaceAll(",",
			// ",").split(","), ",");
			sb.append(" order by ").append(orderBy);
		} else {
			sb.append(" order by n.objId0, n.objId1");
		}
		List<SoaNexus> lt = dao.list(sb.toString(), pageNo, pageSize);
		return new PagedResult<SoaNexus>(total, lt, pageNo, pageSize);
	}

	@Override
	public PagedResult<SoaNexus> listSubflow(String flowId, String key, String orderBy, int pageNo, int pageSize) {
		return this.list(flowId, "subflow", key, orderBy, pageNo, pageSize);
	}
}